#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include "..\Core\System.cu\cuPrintf.cu"
#include "..\Core\System.cu\cuFalloc.cu"
#include "..\Core\System\LinkedList.h"

using namespace System;

template class LinkedList<int>;

__global__ void testLinkedList(fallocHeap* heap)
{
	fallocInit(heap);
	fallocContext* ctx = fallocCreateCtx(heap);

	//
	LinkedList<int> list; list.xtor(ctx);
	list.AddLast(5);
	list.AddLast(3);
	list.AddLast(1);
	list.AddLast(2);
	list.AddLast(7);
	list.AddLast(10);

	//
	LinkedList<int>::Enumerator e; list.GetEnumerator(e);
	while (e.MoveNext(&list))
		cuPrintf("%d\n", e.Current);
	e.Dispose();

	//
	fallocDisposeCtx(ctx);
}

int main()
{
	cudaFallocHost fallocHost = cudaFallocInit(2048);
	cudaPrintfInit(256000);

	// test
	testLinkedList<<<1, 1>>>(fallocHost.heap);

	// free and exit
	cudaPrintfDisplay(stdout, true); cudaPrintfEnd();
	cudaFallocEnd(fallocHost);
	printf("\ndone.\n"); //char c; scanf_s("%c", &c);
    return 0;
}
